from osgeo import gdal


def Tif2tfw_algorithm(filepath: str):
    """
    Here is where the processing itself takes place.
    """

    # Retrieve the feature source and sink. The 'dest_id' variable is used
    # to uniquely identify the feature sink, and must be included in the
    # dictionary returned by the processAlgorithm function.
    is_ok = False
    rlayer = gdal.Open(str(filepath))
    affinetransform = rlayer.GetGeoTransform()
    # print(affinetransform)
    tfw_content = ''
    for i in [1, 2, 4, 5, 0, 3]:
        tfw_content += f'{abs(affinetransform[i])}\n'
    out_filepath = filepath.split('.')[0] + '.tfw'
    with open(out_filepath, 'w') as f:
        f.write(tfw_content)
        is_ok = True
    return {'output_path': out_filepath, 'is_ok': is_ok}
